package top.saodisheng.springcloud.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;

/**
 * Description:
 * @configuration--spring applicationContext.xml
 * @author 扫地生_saodisheng
 */
@Configuration
public class ConfigBean {

        /**
         * 配置负载均衡实现RestTemplate
         * IRule
         * RoundRobinRule 轮询
         * RandomRule 随机
         * AvailabilityFilteringRule 会先过滤掉跳闸、访问故障的服务...然后对剩下的进行轮询
         * RetryRule 会先按照轮询获取服务...如果服务获取失败，则会在指定的时间内进行重试
         * @return
         */
//        // 配置RestTemplate
//        @Bean
//        @LoadBalanced
//        public RestOperations restTemplate(RestTemplateBuilder builder) {
//            return builder.build();
//        }
        @Bean
        @LoadBalanced //配置负载均衡实现RestTemplate
        public RestTemplate getRestTemplate() {
                return new RestTemplate();
        }

//    @Bean
//    public IRule myRule() {
//        return new RandomRule();
//    }
}
